package Midium;

public class Solution6_2 {
    public static String convert(String s, int numRows) {
        if(numRows == 1 )
            return s;
        String result="";
        StringBuffer res[] = new StringBuffer[numRows];
        for(int i = 0 ; i < res.length ; i++)
            res[i] = new StringBuffer();// 初始化
        boolean positive = true;
        for(int i = 0,j=-1 ; i < s.length();i++){ //遍历第i个数，j是指存放到第几行
            if(positive)
                res[++j].append(s.charAt(i));
            else
                res[--j].append(s.charAt(i));
            if(j==numRows-1||(j==0&&positive==false))
                positive=!positive;
        }
        for(int i = 0 ; i <res.length;i++)
            result+=res[i].toString();
        return result;
    }

    public static void main(String[] args) {
        System.out.println(convert("LEETCODEISHIRING",4));
    }
}
